/*
 * Lenovo Group
 * Copyright (c) 2015-2016 All Rights Reserved.
 * 
 * Project Name:itsm-gateway
 * Create Time: 2016年2月11日 下午10:15:46
 */
package com.lenovo.lmrp.base;

import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;

import com.lenovo.sdc.framework.util.Tuple;

/**
 * Define file read/write common interface, implementation class can read/write in file system or FTP server
 * 
 * @author wujin
 * @version v1.0
 */
public interface IFileService {

    /**
     * write data to File that can be store to file system no matter is local disk or storage system mount to os
     * or remote FTP server
     * 
     * @param relativePath  relative file path with root path that configured in paramter file
     * @param data
     * @return  file absolute path and file size
     */
    public Tuple.Pair<String, Long> writeFile(String relativePath, byte[] data);
    
    /**
     * read data from input stream to save in file. invoker should close input stream to avoid memory leak
     * 
     * @param relativePath
     * @param in
     * @return file absolute path and file size
     */
    public Tuple.Pair<String, Long> writeFile(String relativePath, InputStream in);
    
    /**
     * read file data from absolute path then append to string builder
     * 
     * @param absolutePath file absolute path
     * @param buf
     * @return file size and file size
     */
    public long readFile(String absolutePath, StringBuilder buf);
    
    /**
     * read file data from absolute path then append to bytebuffer. if buff size is less than file size, will enlarge it
     * invoke should release this buffer to avoid memtory leak
     * 
     * @param absolutePath
     * @param buf
     * @return file size
     */
    public long readFile(String absolutePath, ByteBuffer buf);
    
    /**
     * read file data then put to output stream, invoke should close stream after use it.
     * 
     * @param absolutePath
     * @param out
     * @return file size
     */
    public long readFile(String absolutePath, OutputStream out);
    
}
